<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>基于Ajax灾区物资运输管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">新闻资讯</div>
                <div class="layui-card-body ">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-form-item">
                                <div class="layui-form-item layui-form-text">
                                    <input type="text" id="title" name="title" lay-verify="required"
                                           autocomplete="off" class="layui-input" placeholder="请输入新闻标题">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <textarea class="layui-textarea" placeholder="请输入内容" id="content" name="content" class="layui-hide" lay-verify="required"></textarea>
                            </div>
                            <div class="layui-form-item layui-show-xs-block">
                                <button class="layui-btn"  lay-submit="" lay-filter="search">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/xcity.js"></script>
<script>
    layui.use(['laydate','form', 'table', 'layedit'], function(){
        var form = layui.form;
        var layedit = layui.layedit;

        // 创建一个编辑器
        var editIndex = layedit.build("content", {
            // hideTool: ['image']
            uploadImage: {
               url: './news/uploadNewsImage'
               ,type: 'post'
            }
            // tool: []
            // height: 100
        });

        // 自定义工具栏
        // tool: ['strong','italic','underline','del' ,'|','left','center','right','link','unlink','image','face']
        // layedit图片上传后，返回格式 {code: 0, msg: '', data: {src: '图片路径', title: '图片名称'}}

        // 数据提交
        form.on('submit(search)', function (data) {
            var btn = $(this);
            btn.text("数据提交中...").attr("disabled", "disabled").addClass("layui-disabled");
            content = layedit.getContent(editIndex);
            data.field.content = content;
            $.ajax({
               url: './news/insertNewsInfo',
               type: 'post',
               data: data.field,
               dataType: 'json',
               success: function(res) {
                   layer.msg(res.msg, function () {
                       window.location.reload();
                   });
               },
               error: function() {
                   layer.msg("服务器异常");
                   btn.text("提交").attr("disabled", false).removeClass("layui-disabled");
               }
            });
            return false;
        })
    });

</script>
</html>
